"""
URL configuration for main project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.http import JsonResponse, HttpResponse
from django.shortcuts import render
from django.urls import path

# def useragent(request):
#     print(request.META.get('HTTP_USER_AGENT'))
#     print(request.headers.get('User-Agent'))
#     ua = request.headers.get('User-Agent')
#     if ua.startswith('python'):
#         return JsonResponse({'ua':'python111111'})
#     else:
#         return JsonResponse({'useragent':request.headers.get('User-Agent')})
#



# def cookies(request):
#     # 刚开始不传cookies的话是没有cookies的
#     csrftoken = request.COOKIES
#     if not csrftoken:
#         return JsonResponse({"cook":'notntnot'})
#         # 这几个都可以取得cookies
#         # print(request.META)
#         # print(request.headers.get('cookie'),type(request.headers.get('cookie')))
#         # print(request.COOKIES['csrftoken'], type(request.COOKIES))
#
#
#
#     else:
#         return JsonResponse({'cookies': request.COOKIES})



def referer(request):
    # 这两个都可以获取referer
    # print(request.META.get('HTTP_REFERER'))
    # print(request.headers.get('HTTP_REFERER'))
    referer = request.META.get('HTTP_REFERER')

    # if  referer.startswith("http://127.0.0.1:8000"):
    #     return JsonResponse({'referer': request.META.get('HTTP_REFERER')})
    #
    #
    # else:
    #     return JsonResponse({'referer': "referernot"})



def js_nx(request):
    return render(request, 'js_nx.html')


urlpatterns = [
    path('admin/', admin.site.urls),
    # path('useragent/', useragent),
    # path('cookies/', cookies),
    path('referer/', referer),
    path('js_nx/',js_nx),
]
